﻿using System.ComponentModel;
using System.Windows.Forms;
using System.Collections.Generic;
using DotNet.Common;

namespace DotNet.Common
{
    public partial class ChannelNamePanel : DynamicPanel<ChannelName>
    {
        string[] m_allChannelList;

        public string[] AllChannelList
        {
            set
            {
                m_allChannelList = value;
            }
        }

        /// <summary>
        /// 通道名称
        /// </summary>
        public string[] ShowList
        {
            set
            {
                Clear();

                if (value.Length == 0)
                {
                    this.Add();
                }
                else
                {
                    int index = 0;
                    foreach (string label in value)
                    {
                        ChannelName oChannelName = this.Add();
                        oChannelName.Label = label;
                        index++;
                    }
                }
            }
            get
            {
                int i = 0;
                string[] nameList = new string[this.Controls.Count];
                foreach (ChannelName channelName in this.Controls)
                {
                    nameList[i] = channelName.Label;
                    i++;
                }

                return nameList;
            }
        }

        public ChannelNamePanel()
        {
            InitializeComponent();
            Initialize();
        }

        public ChannelNamePanel(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
            Initialize();
        }

        protected override void Initialize()
        {
            this.OnAdd += new ControlHandler(ChannelNamePanel_OnAdd);
        }

        void ChannelNamePanel_OnAdd(UserControl control)
        {
            (control as ChannelName).ChannelList = m_allChannelList;
        }
    }
}
